﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.Business;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for UserDalTest and is intended
    ///to contain all UserDalTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetUserByEmail
        ///</summary>
        [TestMethod()]
        public void GetUserByEmailTestFail()
        {
            string email = "xyz@somemail.com"; // TODO: Initialize to an appropriate value
            User expected = null;
            User actual;
            actual = UserDataAccess.GetUserByEmail(email);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ChangeUserPassword
        ///</summary>
        [TestMethod()]
        public void ChangeUserPasswordTest()
        {
            Random rand = new Random();
            string email = "test" + rand.Next(500) + "@test.com";
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, email, "saramontano1", "saramontano1", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string password = "saramontano1";
            string newpass = "saramontano2";
            string renewpass = "saramontano2";
            User user = UserPasswordUpdateManager.UpdatePassword(email, password, newpass, renewpass);  
        }

        /// <summary>
        ///A test for CancelUserAccount
        ///</summary>
        [TestMethod()]
        public void CancelUserAccountTest()
        {
            Random rand = new Random();
            string email = "test" + rand.Next(500) + "@test.com";
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, email, "saramontano1", "saramontano1", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string password = "saramontano1";
            User user = UserCancelAccountManager.CancelUserAccount(email, password);
        }

        /// <summary>
        ///A test for GetUserById
        ///</summary>
        [TestMethod()]
        public void GetUserByIdTest()
        {
            Random rand = new Random();
            string email = "test" + rand.Next(500) + "@test.com";
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, email, "saramontano1", "saramontano1", "Cochabamba", "Cochabamba", "79718989", "4483251");
            long id = 1; // TODO: Initialize to an appropriate value
            User expected = null; // TODO: Initialize to an appropriate value
            User actual;
            actual = UserDataAccess.GetUserById(id);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetUserByName
        ///</summary>
        [TestMethod()]
        public void GetUserByNameTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            //string email = "juan@hotmail.com";
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            object expected = null; // TODO: Initialize to an appropriate value
            object actual;
            actual = UserDataAccess.GetUserByName(firstName);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for ReactiveUserAccount
        ///</summary>
        [TestMethod()]
        public void ReactiveUserAccountTest()
        {
            Random rand = new Random();
            string email = "test" + rand.Next(500) + "@test.com";
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, email, "saramontano1", "saramontano1", "Cochabamba", "Cochabamba", "79718989", "4483251");
            User user = UserDataAccess.GetUserByEmail(email);
            UserCancelAccountManager.ReactiveUserAccount(user);
        }
    }
}
